package at.fhj.pse.datasource.model;

import javax.persistence.Entity;

import java.io.Serializable;

import javax.persistence.Id;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Column;
import javax.persistence.OneToMany;

import at.fhj.pse.datasource.exception.DatasourceLayerException;

import java.lang.Override;
import java.util.List;

@Entity
public class Department implements Serializable {

	private static final long serialVersionUID = 8914611053100493143L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "id", updatable = false, nullable = false)
	private Long id = null;

	public List<Employee> getEmployees() {
		return employees;
	}

	public void setEmployees(List<Employee> employees) {
		if (employees == null) {
			throw new DatasourceLayerException("employees is null", new IllegalArgumentException());
		}
		this.employees = employees;
	}

	@Column(nullable = false)
	private String description;

	@OneToMany(mappedBy="department")
	private List<Employee> employees;
	
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		if (description == null) {
			throw new DatasourceLayerException("description is null", new IllegalArgumentException());
		}
		this.description = description;
	}

	public Long getId() {
		return this.id;
	}

	public void setId(final Long id) {
		this.id = id;
	}

	@Override
	public boolean equals(Object that) {
		if (this == that) {
			return true;
		}
		if (that == null) {
			return false;
		}
		if (getClass() != that.getClass()) {
			return false;
		}
		if (id != null) {
			return id.equals(((Department) that).id);
		}
		return super.equals(that);
	}

	@Override
	public int hashCode() {
		if (id != null) {
			return id.hashCode();
		}
		return super.hashCode();
	}

	@Override
	public String toString() {
		return this.description;
	}
}